package com.linser.gistools;

import com.linser.gistools.refactoring.geotools.JMapPaneNew;
import com.linser.gistools.utils.GlobalVariables;
import javafx.embed.swing.SwingNode;
import javafx.fxml.FXML;
import javafx.scene.layout.StackPane;
import org.geotools.map.MapContent;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.referencing.FactoryException;

import java.awt.*;

public class MainController {
    @FXML
    private StackPane mapPaneContainer;

    @FXML
    private SwingNode swingNodeJMapPaneNew;

    @FXML
    private void initialize() throws FactoryException {
        // 创建 GeoTools 地图内容
        MapContent mapContent = new MapContent();
        // 定义地理坐标系为 WGS84
        DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
        // 定义默认坐标系
        //CoordinateReferenceSystem crs = CRS.decode("EPSG:3857");
        // 设置地理坐标系
        mapContent.getViewport().setCoordinateReferenceSystem(crs);
        // 创建 JMapPane 并设置地图内容
        JMapPaneNew mapPane = new JMapPaneNew(mapContent);
        mapPane.setBackground(Color.WHITE);

        GlobalVariables.jMapPane = mapPane;
        GlobalVariables.mapContent = mapContent;
        GlobalVariables.mapPaneContainer = mapPaneContainer;
        this.swingNodeJMapPaneNew.setContent(mapPane);
    }
}